# == Schema Information
#
# Table name: users
#
#  id                :integer          not null, primary key
#  user_id           :string
#  name              :string
#  phone             :string
#  user_type         :string
#  user_count        :integer          default(1)
#  go_ann            :string
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  choose_party      :boolean          default(FALSE)
#  choose_anne_party :boolean          default(FALSE)
#  is_choosen        :boolean          default(FALSE)
#  level             :integer          default(0)
#

class User < ApplicationRecord
  def self.to_csv
    CSV.generate({col_sep: "\t"}) do |csv|
      users = all
      names = %w(等级 员工ID 姓名 手机号 购票数量)
      csv << names
      users.each do |user|
        csv_array = []
        csv_array << "VIP#{user.user_type}"
        csv_array << user.user_id
        csv_array << user.name
        csv_array << user.phone
        csv_array << user.user_count
        csv << csv_array.dup
      end
    end.encode('gb2312', :invalid => :replace, :undef => :replace, :replace => "?")
    # end.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => "?")
  end
end
